package leetcode;

import java.util.*;
import java.util.stream.Collectors;

public class LC703KthLargest {
    public int k ;
    public List<Integer> nums;
    public PriorityQueue<Integer> queue;

    public LC703KthLargest(int k, int[] nums) {
        this.k = k;
        this.nums = Arrays.stream(nums).boxed().collect(Collectors.toList());
        this.queue = new PriorityQueue<>();
        for (int i = 0; i < nums.length; i++) {
            add(nums[i]);
        }
    }

    public int add(int val) {
        queue.offer(val);
        if (queue.size() > k) {
            queue.poll();
        }
        return queue.peek();
    }

    public static void main(String[] args) {

        int[] intArray = {1, 2, 3, 4, 5};
        List<Integer> arrayList = Arrays.stream(intArray).boxed().collect(Collectors.toList());

        // 输出以验证转换结果
        for (Integer number : arrayList) {
            System.out.println(number);
        }


    }
}
